<template>
	<div style="height: 100%;">
		<div class="displayFlex mb10">
			<el-input placeholder="客户名称" v-model="params.entName" style="width: 250px;" clearable></el-input>

			<el-button type="primary" style="margin-left: 10px;" icon="el-icon-search" @click="getList()">确定</el-button>
		</div>
		<el-table tooltip-effect="dark" :data="tableData" v-loading.body="listLoading" ref="dataSelectTable" border
			style="width: 100%;overflow-y: auto;" :height="height*0.7+'px'">
			<el-table-column label="客户名称" prop="entName">
				<template scope="scope">
					{{scope.row.entName||'--'}}
				</template>
			</el-table-column>
			<el-table-column label="状态" width="100" align="center">
				<template scope="scope">
					<el-tag type="success" v-if="scope.row.isChecked" size="small">当前企业</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="100" align="center">
				<template scope="scope">
					<el-button type="text" @click="chooseThis(scope.row)">选择</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div v-show="tableData&&tableData.length>0" align="right" class="mt10">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page.sync="pageIndex" :page-sizes="[10,20,30,50]" :page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</div>

	</div>
</template>

<script>
	let that

	export default {
		components: {},
		data() {
			return {
				height: window.innerHeight,
				tableData: [],
				listLoading: true,
				pageIndex: 1,
				pageSize: 10,
				total: 0,
				params: {
					entName: '',
					ticketId: ''
				},
			}
		},
		mounted: function() {
			that = this
			that.params.ticketId = that.$store.state.token

			that.getList()
		},
		methods: {

			chooseThis(custom) {
				localStorage.setItem("custom", JSON.stringify(custom))
				// that.bus.$emit('onCurrentContextmenuClick', {
				// 	id: 3,
				// 	path: this.$route.path,
				// });
				that.$message.success(`切换成功，正在加载中...`);
				setTimeout(() => {
					that.$router.push('/home');
					window.location.reload()
				}, 1000);
			},

			getList: function() {
				var _this = this;
				var param = JSON.parse(JSON.stringify(_this.params));
				_this.listLoading = true;
				that.ajax({
					url: '/bbep/serve/ent/pageLabelEnt?ticketId=' + that.params.ticketId +
						'&pageIndex=' + _this
						.pageIndex + '&pageSize=' + _this.pageSize,
					dataType: 'json',
					data: JSON.stringify(param),
					contentType: 'application/json',
					success: function(result) {
						_this.listLoading = false;
						if (result.status == 1 && result.data) {
							let records = result.data.records

							if (localStorage.getItem("custom")) {
								let custom = JSON.parse(localStorage.getItem("custom"))

								for (let item of records) {
									item.isChecked = false
									if (item.entId == custom.entId) {
										item.isChecked = true
									}
								}
							}
							_this.total = result.data.total;
							_this.tableData = result.data.records;
						} else {
							_this.tableData = [];
							_this.total = 0;
						}
					}
				})
			},

			handleSizeChange: function(val) {
				this.pageIndex = 1;
				this.pageSize = val;
				this.getList();
			},
			handleCurrentChange: function(val) {
				this.pageIndex = val;
				this.getList();
			},

		}
	}
</script>